//
//  LGLifelogViewController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/8/9.
//

#import "LGLifelogViewController.h"
#import "LGSportsRecordController.h"
#import "LGDietRecordViewController.h"
//戒烟
#import "LGSmokingRecordController.h"
//戒酒
#import "LGDrinkRecordController.h"
@interface LGLifelogViewController ()
/**   */
@property (nonatomic , strong)LGNavigationView *navigationView;
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)LGSportsRecordController *sportVC;
/**   */
@property (nonatomic , strong)LGDietRecordViewController *dietVC;
/**   */
@property (nonatomic , strong)LGSmokingRecordController *smokeVC;
/**   */
@property (nonatomic , strong)LGDrinkRecordController *drinkVC;
/**   */
@property (nonatomic , strong)NSMutableArray *controllerArray;
/**   */
@property (nonatomic , strong)NSArray *titleArray;
@end

@implementation LGLifelogViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationView.title = @"生活方式记录";
    [self commonInit];
    [self reloadData];
    self.scrollView.backgroundColor = [UIColor clearColor];
}

-(void)backButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark
#pragma mark ====> WMPageControllerDelegate
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titleArray.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titleArray[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    return self.controllerArray[index];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    return (Screen_W-20)/4.0;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, topBarHeight, Screen_W, viewPix(44));
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    return CGRectMake(0, topBarHeight+viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44));
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    LGBaseViewController *controller = (LGBaseViewController *)viewController;
//    [controller viewWillAppearAction];
    NSLog(@">>>>>willEnterView>>>%@",viewController.title);
}

- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSLog(@">>>>>didEnterView>>>%@",viewController.title);
}

-(void)commonInit{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = kNavBgColor;
    [self.view addSubview:self.navigationView];
//    [self.view.layer addSublayer:self.gradientLayer];
    self.titleArray = @[@"运动记录",@"饮食记录",@"戒烟记录",@"戒酒记录"];
    [self addChildViewController:self.sportVC];
    [self addChildViewController:self.dietVC];
    [self addChildViewController:self.smokeVC];
    [self addChildViewController:self.drinkVC];
    [self.controllerArray addObject:self.sportVC];
    [self.controllerArray addObject:self.dietVC];
    [self.controllerArray addObject:self.smokeVC];
    [self.controllerArray addObject:self.drinkVC];
    
    self.titleColorNormal = [UIColor colorWithString:@"#666666"];
    self.titleColorSelected = [UIColor colorWithString:@"#4C87FD"];
    self.progressColor = [UIColor colorWithString:@"#3291FF"];
    self.menuViewStyle=WMMenuViewStyleLine;
    self.titleFontName = @"STHeitiTC-Medium";
    self.titleSizeSelected = 16;
    self.titleSizeNormal = 14;
    self.progressWidth = viewPix(13);
    self.progressHeight = 4;
    self.progressViewBottomSpace = 0;
    self.progressViewCornerRadius = 2;
    [self reloadData];
    self.scrollView.backgroundColor = [UIColor clearColor];
}

-(NSMutableArray *)controllerArray{
    if(!_controllerArray){
        _controllerArray = [NSMutableArray array];
    }
    return _controllerArray;
}

-(CAGradientLayer *)gradientLayer{
    if(!_gradientLayer){
        _gradientLayer = [CAGradientLayer layer];
        _gradientLayer.frame = CGRectMake(0,topBarHeight,Screen_W,viewPix(167));
        _gradientLayer.startPoint = CGPointMake(0.5, 0);
        _gradientLayer.endPoint = CGPointMake(0.5, 1.03);
        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F3FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#FEFEFF" alpha:0].CGColor];
        _gradientLayer.locations = @[@(0), @(0.4f), @(1.0f)];
    }
    return _gradientLayer;
}

-(LGNavigationView *)navigationView{
    if(!_navigationView){
        _navigationView = [[LGNavigationView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, topBarHeight)];
        _navigationView.backgroundColor = [UIColor colorWithString:@"#E5F3FF"];
        _navigationView.title = @"报告中心";
        [_navigationView.backBtn addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _navigationView;
}

-(LGSportsRecordController *)sportVC{
    if(!_sportVC){
        _sportVC = [[LGSportsRecordController alloc]init];
        _sportVC.patientid = self.patientid;
    }
    return _sportVC;
}

-(LGDietRecordViewController *)dietVC{
    if(!_dietVC){
        _dietVC = [[LGDietRecordViewController alloc]init];
        _dietVC.patientid = self.patientid;
    }
    return _dietVC;
}

-(LGSmokingRecordController *)smokeVC{
    if(!_smokeVC){
        _smokeVC = [[LGSmokingRecordController alloc] init];
        _smokeVC.patientid = self.patientid;
    }
    return _smokeVC;
}

-(LGDrinkRecordController *)drinkVC{
    if(!_drinkVC){
        _drinkVC = [[LGDrinkRecordController alloc] init];
        _drinkVC.patientid = self.patientid;
    }
    return _drinkVC;
}

@end
